package com.example.onlinemusic.mapper;

import com.example.onlinemusic.model.Music;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MusicMapper {
    // 插入音乐
    @Insert("insert into music (title, singer, time, url, userid)" +
            " values (#{title},#{singer},#{time},#{url},#{userid})")
    int insert(String title, String singer, String time, String url, int userid);

    // 根据 id 删除音乐
    @Delete("delete from music where id = #{musicId}")
    int deleteMusicById(int musicId);

    // 根据 id 查找音乐
    @Select("select * from music where id = #{musicId}")
    Music findMusicById(int musicId);

    // 查询所有的音乐
    @Select("select * from music")
    List<Music> findMusic();

    // 查询指定内容的音乐
    @Select("select * from music where title like concat('%',#{title},'%')")
    List<Music> findMusicByName(String title);

    // 根据 [歌名 + 歌手] 查找音乐
    @Select("select * from music where title = #{title} and singer = #{singer};")
    Music findMusicByNameAndSinger(String title, String singer);
}
